//
//  FileTypeIcon.m
//  MIS Cloud
//
//  Created by goldeney on 13-11-19.
//  Copyright (c) 2013年 goldeneye. All rights reserved.
//

#import "FileTypeIcon.h"
static NSMutableDictionary *fileIconDictionary;

@implementation FileTypeIcon

+ (UIImage*)setFileTypeIcon:(NSString*)filePath
{
    // 获得文件的扩展类型（不带'.'）
    NSString *exeStr = [filePath pathExtension];
    exeStr = [exeStr lowercaseString];//将文字转换成小写
    NSMutableDictionary *fileIcon = [self getFileIconArray];
    NSString *fileIconName = [fileIcon objectForKey:exeStr];
    
    if (fileIconName) {
        return [UIImage imageNamed:fileIconName];
    } else {
        return [self getDefaultIconImage];
    }
}

+ (NSMutableDictionary*) getFileIconArray
{
    if (fileIconDictionary) return fileIconDictionary;
    fileIconDictionary= [[NSMutableDictionary alloc] init];
    [fileIconDictionary setObject:@"apk.png" forKey:@"apk"];
    [fileIconDictionary setObject:@"doc.png" forKey:@"doc"];
    [fileIconDictionary setObject:@"docx.png" forKey:@"docx"];
    [fileIconDictionary setObject:@"gif.png" forKey:@"gif"];
    [fileIconDictionary setObject:@"jpg.png" forKey:@"jpg"];
    [fileIconDictionary setObject:@"pdf.png" forKey:@"pdf"];
    [fileIconDictionary setObject:@"png.png" forKey:@"png"];
    [fileIconDictionary setObject:@"ppt.png" forKey:@"ppt"];
    [fileIconDictionary setObject:@"pptx.png" forKey:@"pptx"];
    [fileIconDictionary setObject:@"txt.png" forKey:@"txt"];
    [fileIconDictionary setObject:@"xls.png" forKey:@"xls"];
    [fileIconDictionary setObject:@"xlsx.png" forKey:@"xlsx"];
    [fileIconDictionary setObject:@"zip.png" forKey:@"zip"];
    [fileIconDictionary setObject:@"rar.png" forKey:@"rar"];
    [fileIconDictionary setObject:@"file_video.png" forKey:@"mov"];
    [fileIconDictionary setObject:@"file_video.png" forKey:@"mp4"];
    [fileIconDictionary setObject:@"file_video.png" forKey:@"wmv"];
    [fileIconDictionary setObject:@"file_video.png" forKey:@"avi"];
    [fileIconDictionary setObject:@"file_audio.png" forKey:@"mp3"];
    [fileIconDictionary setObject:@"file_audio.png" forKey:@"wav"];
    [fileIconDictionary setObject:@"file_audio.png" forKey:@"mmf"];
    [fileIconDictionary setObject:@"file_audio.png" forKey:@"mmm"];
    
    return fileIconDictionary;
}

+ (UIImage*) getDefaultIconImage
{
    return [UIImage imageNamed:@"default_fileicon.png"];
}

+ (UIImage*) getFilerIconImage
{
    return [UIImage imageNamed:@"folder.png"];
}

@end
